using System.Collections;
using System.Net.Mail;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;

namespace Sage.Data.Validation
{

    /// <summary>
    /// 自定义参数验证辅助类，扩展 .NET 内置的参数验证功能
    /// <para>提供丰富的参数验证方法，支持自定义错误消息</para>
    /// <para>命名遵循 ArgumentXxxException 模式，便于开发者快速发现和使用</para>
    /// </summary>
    /// <remarks>
    /// 使用方式：
    /// <code>
    /// ArgumentCustomException.ThrowIfNull(parameter, nameof(parameter));
    /// ArgumentCustomException.ThrowIfNullOrEmpty(text, nameof(text), "自定义错误消息");
    /// </code>
    /// </remarks>
    public static class ArgumentCustomException
    {
        #region Null 和基础验证

        /// <summary>
        /// 验证引用类型参数不为 null
        /// </summary>
        /// <typeparam name="T">引用类型参数</typeparam>
        /// <param name="argument">要验证的参数值</param>
        /// <param name="paramName">参数名称，通常使用 nameof(parameter)</param>
        /// <param name="message">自定义错误消息，为 null 时使用默认消息</param>
        /// <returns>验证通过的参数值，支持链式调用</returns>
        /// <exception cref="ArgumentNullException">参数为 null 时抛出</exception>
        /// <example>
        /// <code>
        /// var user = ArgumentCustomException.ThrowIfNull(userInput, nameof(userInput));
        /// ArgumentCustomException.ThrowIfNull(service, nameof(service), "服务实例不能为空");
        /// </code>
        /// </example>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIfNull<T>(T argument, string paramName, string? message = null)
            where T : class
        {
            if (argument == null)
            {
                throw new ArgumentNullException(paramName, message ?? $"参数 {paramName} 不能为 null");
            }
            return argument;
        }

        /// <summary>
        /// 验证可空值类型参数不为 null
        /// </summary>
        /// <typeparam name="T">值类型参数</typeparam>
        /// <param name="argument">要验证的可空值类型参数</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的值类型参数</returns>
        /// <exception cref="ArgumentNullException">可空值类型为 null 时抛出</exception>
        /// <example>
        /// <code>
        /// int age = ArgumentCustomException.ThrowIfNull(ageInput, nameof(ageInput));
        /// DateTime date = ArgumentCustomException.ThrowIfNull(dateInput, nameof(dateInput), "日期不能为空");
        /// </code>
        /// </example>
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static T ThrowIfNull<T>(T? argument, string paramName, string? message = null)
            where T : struct
        {
            if (!argument.HasValue)
            {
                throw new ArgumentNullException(paramName, message ?? $"参数 {paramName} 不能为 null");
            }
            return argument.Value;
        }

        /// <summary>
        /// 验证参数等于默认值时抛出异常
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="argument">要验证的参数</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的参数值</returns>
        /// <exception cref="ArgumentException">参数等于默认值时抛出</exception>
        /// <example>
        /// <code>
        /// var guid = ArgumentCustomException.ThrowIfDefault(guidInput, nameof(guidInput));
        /// var date = ArgumentCustomException.ThrowIfDefault(dateInput, nameof(dateInput), "日期不能为默认值");
        /// </code>
        /// </example>
        public static T ThrowIfDefault<T>(T argument, string paramName, string? message = null)
        {
            if (EqualityComparer<T>.Default.Equals(argument, default))
            {
                throw new ArgumentException(message ?? $"参数 {paramName} 不能为默认值", paramName);
            }
            return argument;
        }

        #endregion

        #region 字符串验证

        /// <summary>
        /// 验证字符串参数不为 null 或空字符串
        /// </summary>
        /// <param name="argument">要验证的字符串参数</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的字符串</returns>
        /// <exception cref="ArgumentException">字符串为 null 或空时抛出</exception>
        /// <example>
        /// <code>
        /// var name = ArgumentCustomException.ThrowIfNullOrEmpty(nameInput, nameof(nameInput));
        /// var id = ArgumentCustomException.ThrowIfNullOrEmpty(idInput, nameof(idInput), "ID 不能为空");
        /// </code>
        /// </example>
        public static string ThrowIfNullOrEmpty(string argument, string paramName, string? message = null)
        {
            if (string.IsNullOrEmpty(argument))
            {
                throw new ArgumentException(message ?? $"参数 {paramName} 不能为 null 或空字符串", paramName);
            }
            return argument;
        }

        /// <summary>
        /// 验证字符串参数不为 null、空字符串或只包含空白字符
        /// </summary>
        /// <param name="argument">要验证的字符串参数</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的字符串</returns>
        /// <exception cref="ArgumentException">字符串为 null、空或只包含空白字符时抛出</exception>
        /// <example>
        /// <code>
        /// var comment = ArgumentCustomException.ThrowIfNullOrWhiteSpace(commentInput, nameof(commentInput));
        /// var description = ArgumentCustomException.ThrowIfNullOrWhiteSpace(descInput, nameof(descInput), "描述不能为空白");
        /// </code>
        /// </example>
        public static string ThrowIfNullOrWhiteSpace(string argument, string paramName, string? message = null)
        {
            if (string.IsNullOrWhiteSpace(argument))
            {
                throw new ArgumentException(message ?? $"参数 {paramName} 不能为 null、空字符串或只包含空白字符", paramName);
            }
            return argument;
        }

        /// <summary>
        /// 验证字符串长度在指定范围内
        /// </summary>
        /// <param name="argument">要验证的字符串</param>
        /// <param name="minLength">最小长度（包含）</param>
        /// <param name="maxLength">最大长度（包含）</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的字符串</returns>
        /// <exception cref="ArgumentNullException">字符串为 null 时抛出</exception>
        /// <exception cref="ArgumentException">字符串长度超出范围时抛出</exception>
        /// <example>
        /// <code>
        /// var username = ArgumentCustomException.ThrowIfLengthOutOfRange(usernameInput, 3, 20, nameof(usernameInput));
        /// var password = ArgumentCustomException.ThrowIfLengthOutOfRange(passwordInput, 8, 50, nameof(passwordInput), "密码长度必须在8-50字符之间");
        /// </code>
        /// </example>
        public static string ThrowIfLengthOutOfRange(string argument, int minLength, int maxLength,
            string paramName, string? message = null)
        {
            ThrowIfNull(argument, paramName);

            if (minLength < 0)
                throw new ArgumentOutOfRangeException(nameof(minLength), "最小长度不能为负数");

            if (maxLength < minLength)
                throw new ArgumentOutOfRangeException(nameof(maxLength), "最大长度不能小于最小长度");

            if (argument.Length < minLength || argument.Length > maxLength)
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 的长度必须在 {minLength} 到 {maxLength} 之间，当前长度: {argument.Length}",
                    paramName);
            }
            return argument;
        }

        /// <summary>
        /// 验证字符串匹配指定的正则表达式模式
        /// </summary>
        /// <param name="argument">要验证的字符串</param>
        /// <param name="pattern">正则表达式模式</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <param name="regexOptions">正则表达式选项，默认为 None</param>
        /// <returns>验证通过的字符串</returns>
        /// <exception cref="ArgumentException">字符串不匹配模式时抛出</exception>
        /// <example>
        /// <code>
        /// var phoneNumber = ArgumentCustomException.ThrowIfNotMatch(phoneInput, @"^1[3-9]\d{9}$", nameof(phoneInput), "手机号格式不正确");
        /// var code = ArgumentCustomException.ThrowIfNotMatch(codeInput, @"^[A-Z0-9]{6}$", nameof(codeInput));
        /// </code>
        /// </example>
        public static string ThrowIfNotMatch(string argument, string pattern, string paramName,
            string? message = null, RegexOptions regexOptions = RegexOptions.None)
        {
            ThrowIfNullOrEmpty(argument, paramName);
            ThrowIfNullOrEmpty(pattern, nameof(pattern));

            try
            {
                if (!Regex.IsMatch(argument, pattern, regexOptions))
                {
                    throw new ArgumentException(
                        message ?? $"参数 {paramName} 不匹配要求的格式", paramName);
                }
            }
            catch (RegexMatchTimeoutException)
            {
                throw new ArgumentException($"正则表达式匹配超时: {pattern}", nameof(pattern));
            }
            catch (ArgumentException ex) when (ex.ParamName == nameof(pattern))
            {
                throw new ArgumentException($"无效的正则表达式模式: {pattern}", nameof(pattern));
            }

            return argument;
        }

        #endregion

        #region 数值范围验证

        /// <summary>
        /// 验证数值参数在指定范围内（包含边界值）
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="min">最小值（包含）</param>
        /// <param name="max">最大值（包含）</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值超出范围时抛出</exception>
        /// <example>
        /// <code>
        /// var age = ArgumentCustomException.ThrowIfOutOfRange(ageInput, 0, 150, nameof(ageInput));
        /// var price = ArgumentCustomException.ThrowIfOutOfRange(priceInput, 0.01m, 999999.99m, nameof(priceInput), "价格必须在0.01到999999.99之间");
        /// </code>
        /// </example>
        public static T ThrowIfOutOfRange<T>(T argument, T min, T max, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (min.CompareTo(max) > 0)
                throw new ArgumentException("最小值不能大于最大值", nameof(min));

            if (argument.CompareTo(min) < 0 || argument.CompareTo(max) > 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须在 {min} 到 {max} 之间，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数为正数（大于零）
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的数值类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值小于等于零时抛出</exception>
        /// <example>
        /// <code>
        /// var count = ArgumentCustomException.ThrowIfNotPositive(countInput, nameof(countInput));
        /// var amount = ArgumentCustomException.ThrowIfNotPositive(amountInput, nameof(amountInput), "金额必须为正数");
        /// </code>
        /// </example>
        public static T ThrowIfNotPositive<T>(T argument, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(default) <= 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须为正数，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数不为负数（大于等于零）
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的数值类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值为负数时抛出</exception>
        /// <example>
        /// <code>
        /// var index = ArgumentCustomException.ThrowIfNegative(indexInput, nameof(indexInput));
        /// var balance = ArgumentCustomException.ThrowIfNegative(balanceInput, nameof(balanceInput), "余额不能为负数");
        /// </code>
        /// </example>
        public static T ThrowIfNegative<T>(T argument, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(default) < 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 不能为负数，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数不为零
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的数值类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值为零时抛出</exception>
        /// <example>
        /// <code>
        /// var divisor = ArgumentCustomException.ThrowIfZero(divisorInput, nameof(divisorInput));
        /// var multiplier = ArgumentCustomException.ThrowIfZero(multiplierInput, nameof(multiplierInput), "乘数不能为零");
        /// </code>
        /// </example>
        public static T ThrowIfZero<T>(T argument, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(default) == 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 不能为零");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数大于指定值
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="other">比较基准值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值不大于指定值时抛出</exception>
        /// <example>
        /// <code>
        /// var score = ArgumentCustomException.ThrowIfNotGreaterThan(scoreInput, 60, nameof(scoreInput), "分数必须大于60");
        /// var temperature = ArgumentCustomException.ThrowIfNotGreaterThan(tempInput, -273.15, nameof(tempInput));
        /// </code>
        /// </example>
        public static T ThrowIfNotGreaterThan<T>(T argument, T other, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(other) <= 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须大于 {other}，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数大于等于指定值
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="other">比较基准值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值不大于等于指定值时抛出</exception>
        /// <example>
        /// <code>
        /// var quantity = ArgumentCustomException.ThrowIfLessThan(quantityInput, 1, nameof(quantityInput));
        /// var priority = ArgumentCustomException.ThrowIfLessThan(priorityInput, 0, nameof(priorityInput), "优先级不能小于0");
        /// </code>
        /// </example>
        public static T ThrowIfLessThan<T>(T argument, T other, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(other) < 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须大于等于 {other}，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数小于指定值
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="other">比较基准值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值不小于指定值时抛出</exception>
        /// <example>
        /// <code>
        /// var percentage = ArgumentCustomException.ThrowIfNotLessThan(percentageInput, 100, nameof(percentageInput));
        /// var index = ArgumentCustomException.ThrowIfNotLessThan(indexInput, maxCount, nameof(indexInput), "索引超出范围");
        /// </code>
        /// </example>
        public static T ThrowIfNotLessThan<T>(T argument, T other, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(other) >= 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须小于 {other}，当前值: {argument}");
            }
            return argument;
        }

        /// <summary>
        /// 验证数值参数小于等于指定值
        /// </summary>
        /// <typeparam name="T">实现 IComparable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的数值</param>
        /// <param name="other">比较基准值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的数值</returns>
        /// <exception cref="ArgumentOutOfRangeException">数值不小于等于指定值时抛出</exception>
        /// <example>
        /// <code>
        /// var discount = ArgumentCustomException.ThrowIfGreaterThan(discountInput, 0.5, nameof(discountInput));
        /// var timeout = ArgumentCustomException.ThrowIfGreaterThan(timeoutInput, 300000, nameof(timeoutInput), "超时时间不能超过5分钟");
        /// </code>
        /// </example>
        public static T ThrowIfGreaterThan<T>(T argument, T other, string paramName, string? message = null)
            where T : IComparable<T>
        {
            if (argument.CompareTo(other) > 0)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须小于等于 {other}，当前值: {argument}");
            }
            return argument;
        }

        #endregion

        #region 集合验证

        /// <summary>
        /// 验证集合不为 null 且不为空
        /// </summary>
        /// <typeparam name="T">集合元素类型</typeparam>
        /// <param name="argument">要验证的集合</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的集合</returns>
        /// <exception cref="ArgumentNullException">集合为 null 时抛出</exception>
        /// <exception cref="ArgumentException">集合为空时抛出</exception>
        /// <example>
        /// <code>
        /// var items = ArgumentCustomException.ThrowIfNullOrEmpty(itemsInput, nameof(itemsInput));
        /// var users = ArgumentCustomException.ThrowIfNullOrEmpty(usersInput, nameof(usersInput), "用户列表不能为空");
        /// </code>
        /// </example>
        public static IEnumerable<T> ThrowIfNullOrEmpty<T>(IEnumerable<T> argument, string paramName, string? message = null)
        {
            if (argument == null)
            {
                throw new ArgumentNullException(paramName, message ?? $"集合参数 {paramName} 不能为 null");
            }

            if (!argument.Any())
            {
                throw new ArgumentException(message ?? $"集合参数 {paramName} 不能为空", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证集合元素数量在指定范围内
        /// </summary>
        /// <typeparam name="T">集合元素类型</typeparam>
        /// <param name="argument">要验证的集合</param>
        /// <param name="minCount">最小元素数量（包含）</param>
        /// <param name="maxCount">最大元素数量（包含）</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的集合</returns>
        /// <exception cref="ArgumentNullException">集合为 null 时抛出</exception>
        /// <exception cref="ArgumentException">集合元素数量超出范围时抛出</exception>
        /// <example>
        /// <code>
        /// var tags = ArgumentCustomException.ThrowIfCountOutOfRange(tagsInput, 1, 10, nameof(tagsInput));
        /// var options = ArgumentCustomException.ThrowIfCountOutOfRange(optionsInput, 2, 5, nameof(optionsInput), "选项数量必须在2-5之间");
        /// </code>
        /// </example>
        public static IEnumerable<T> ThrowIfCountOutOfRange<T>(IEnumerable<T> argument, int minCount, int maxCount,
            string paramName, string? message = null)
        {
            ThrowIfNull(argument, paramName);

            if (minCount < 0)
                throw new ArgumentOutOfRangeException(nameof(minCount), "最小数量不能为负数");

            if (maxCount < minCount)
                throw new ArgumentOutOfRangeException(nameof(maxCount), "最大数量不能小于最小数量");

            var count = argument.Count();
            if (count < minCount || count > maxCount)
            {
                throw new ArgumentException(
                    message ?? $"集合 {paramName} 的元素数量必须在 {minCount} 到 {maxCount} 之间，当前数量: {count}",
                    paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证集合中不包含 null 元素
        /// </summary>
        /// <typeparam name="T">集合元素类型（引用类型）</typeparam>
        /// <param name="argument">要验证的集合</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的集合</returns>
        /// <exception cref="ArgumentNullException">集合为 null 时抛出</exception>
        /// <exception cref="ArgumentException">集合包含 null 元素时抛出</exception>
        /// <example>
        /// <code>
        /// var names = ArgumentCustomException.ThrowIfContainsNull(namesInput, nameof(namesInput));
        /// var services = ArgumentCustomException.ThrowIfContainsNull(servicesInput, nameof(servicesInput), "服务列表不能包含空项");
        /// </code>
        /// </example>
        public static IEnumerable<T> ThrowIfContainsNull<T>(IEnumerable<T> argument, string paramName, string? message = null)
            where T : class
        {
            ThrowIfNull(argument, paramName);

            if (argument.Any(item => item == null))
            {
                throw new ArgumentException(
                    message ?? $"集合 {paramName} 不能包含 null 元素", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证数组或列表的索引在有效范围内
        /// </summary>
        /// <param name="index">要验证的索引</param>
        /// <param name="collectionCount">集合的元素总数</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的索引</returns>
        /// <exception cref="ArgumentOutOfRangeException">索引超出有效范围时抛出</exception>
        /// <example>
        /// <code>
        /// var validIndex = ArgumentCustomException.ThrowIfIndexOutOfRange(indexInput, items.Count, nameof(indexInput));
        /// var position = ArgumentCustomException.ThrowIfIndexOutOfRange(posInput, array.Length, nameof(posInput), "位置索引无效");
        /// </code>
        /// </example>
        public static int ThrowIfIndexOutOfRange(int index, int collectionCount, string paramName, string? message = null)
        {
            if (collectionCount < 0)
                throw new ArgumentOutOfRangeException(nameof(collectionCount), "集合大小不能为负数");

            if (index < 0 || index >= collectionCount)
            {
                throw new ArgumentOutOfRangeException(paramName, index,
                    message ?? $"索引 {paramName} 必须在 0 到 {collectionCount - 1} 之间，当前值: {index}");
            }
            return index;
        }

        #endregion

        #region 业务特定验证

        /// <summary>
        /// 验证邮箱地址格式的有效性
        /// </summary>
        /// <param name="argument">要验证的邮箱地址</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的邮箱地址</returns>
        /// <exception cref="ArgumentException">邮箱格式无效时抛出</exception>
        /// <example>
        /// <code>
        /// var email = ArgumentCustomException.ThrowIfInvalidEmail(emailInput, nameof(emailInput));
        /// var adminEmail = ArgumentCustomException.ThrowIfInvalidEmail(adminEmailInput, nameof(adminEmailInput), "管理员邮箱格式不正确");
        /// </code>
        /// </example>
        public static string ThrowIfInvalidEmail(string argument, string paramName, string? message = null)
        {
            ThrowIfNullOrWhiteSpace(argument, paramName);

            try
            {
                var mailAddress = new MailAddress(argument);
                // 确保邮箱地址完全匹配，没有额外的字符
                if (mailAddress.Address != argument.Trim())
                {
                    throw new ArgumentException(
                        message ?? $"参数 {paramName} 不是有效的邮箱地址", paramName);
                }
            }
            catch (FormatException)
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 不是有效的邮箱地址", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证 URL 地址格式的有效性
        /// </summary>
        /// <param name="argument">要验证的 URL 地址</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <param name="allowRelative">是否允许相对 URL，默认为 false</param>
        /// <returns>验证通过的 URL 地址</returns>
        /// <exception cref="ArgumentException">URL 格式无效时抛出</exception>
        /// <example>
        /// <code>
        /// var website = ArgumentCustomException.ThrowIfInvalidUrl(websiteInput, nameof(websiteInput));
        /// var apiUrl = ArgumentCustomException.ThrowIfInvalidUrl(apiUrlInput, nameof(apiUrlInput), "API地址格式不正确");
        /// var relativeUrl = ArgumentCustomException.ThrowIfInvalidUrl(relativeUrlInput, nameof(relativeUrlInput), null, true);
        /// </code>
        /// </example>
        public static string ThrowIfInvalidUrl(string argument, string paramName, string? message = null, bool allowRelative = false)
        {
            ThrowIfNullOrWhiteSpace(argument, paramName);

            var uriKind = allowRelative ? UriKind.RelativeOrAbsolute : UriKind.Absolute;

            if (!Uri.TryCreate(argument, uriKind, out var result))
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 不是有效的 URL 地址", paramName);
            }

            // 如果不允许相对路径，确保是绝对路径
            if (!allowRelative && !result.IsAbsoluteUri)
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 必须是绝对 URL 地址", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证 GUID 不为空值
        /// </summary>
        /// <param name="argument">要验证的 GUID</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的 GUID</returns>
        /// <exception cref="ArgumentException">GUID 为空值时抛出</exception>
        /// <example>
        /// <code>
        /// var userId = ArgumentCustomException.ThrowIfEmptyGuid(userIdInput, nameof(userIdInput));
        /// var sessionId = ArgumentCustomException.ThrowIfEmptyGuid(sessionIdInput, nameof(sessionIdInput), "会话ID不能为空");
        /// </code>
        /// </example>
        public static Guid ThrowIfEmptyGuid(Guid argument, string paramName, string? message = null)
        {
            if (argument == Guid.Empty)
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 不能为空的 GUID", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证枚举值是否为已定义的值
        /// </summary>
        /// <typeparam name="T">枚举类型</typeparam>
        /// <param name="argument">要验证的枚举值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的枚举值</returns>
        /// <exception cref="ArgumentException">枚举值未定义时抛出</exception>
        /// <example>
        /// <code>
        /// var status = ArgumentCustomException.ThrowIfEnumNotDefined(statusInput, nameof(statusInput));
        /// var priority = ArgumentCustomException.ThrowIfEnumNotDefined(priorityInput, nameof(priorityInput), "优先级值无效");
        /// </code>
        /// </example>
        public static T ThrowIfEnumNotDefined<T>(T argument, string paramName, string? message = null)
            where T : struct, Enum
        {
            if (!Enum.IsDefined(argument))
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 包含未定义的枚举值: {argument}", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证文件路径对应的文件是否存在
        /// </summary>
        /// <param name="argument">要验证的文件路径</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的文件路径</returns>
        /// <exception cref="ArgumentException">文件不存在时抛出</exception>
        /// <example>
        /// <code>
        /// var configFile = ArgumentCustomException.ThrowIfFileNotExists(configPath, nameof(configPath));
        /// var dataFile = ArgumentCustomException.ThrowIfFileNotExists(dataPath, nameof(dataPath), "数据文件不存在");
        /// </code>
        /// </example>
        public static string ThrowIfFileNotExists(string argument, string paramName, string? message = null)
        {
            ThrowIfNullOrWhiteSpace(argument, paramName);

            if (!File.Exists(argument))
            {
                throw new ArgumentException(
                    message ?? $"文件路径 {paramName} 指向的文件不存在: {argument}", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证目录路径对应的目录是否存在
        /// </summary>
        /// <param name="argument">要验证的目录路径</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的目录路径</returns>
        /// <exception cref="ArgumentException">目录不存在时抛出</exception>
        /// <example>
        /// <code>
        /// var outputDir = ArgumentCustomException.ThrowIfDirectoryNotExists(outputPath, nameof(outputPath));
        /// var tempDir = ArgumentCustomException.ThrowIfDirectoryNotExists(tempPath, nameof(tempPath), "临时目录不存在");
        /// </code>
        /// </example>
        public static string ThrowIfDirectoryNotExists(string argument, string paramName, string? message = null)
        {
            ThrowIfNullOrWhiteSpace(argument, paramName);

            if (!Directory.Exists(argument))
            {
                throw new ArgumentException(
                    message ?? $"目录路径 {paramName} 指向的目录不存在: {argument}", paramName);
            }

            return argument;
        }

        #endregion

        #region 条件和逻辑验证

        /// <summary>
        /// 验证条件为真，为假时抛出异常
        /// </summary>
        /// <param name="condition">要验证的条件</param>
        /// <param name="paramName">相关的参数名称</param>
        /// <param name="message">错误消息</param>
        /// <exception cref="ArgumentException">条件为假时抛出</exception>
        /// <example>
        /// <code>
        /// ArgumentCustomException.ThrowIfFalse(user.IsActive, nameof(user), "用户必须处于活跃状态");
        /// ArgumentCustomException.ThrowIfFalse(password.Length >= 8, nameof(password), "密码长度必须至少8位");
        /// </code>
        /// </example>
        public static void ThrowIfFalse(bool condition, string paramName, string message)
        {
            if (!condition)
            {
                throw new ArgumentException(message ?? "条件验证失败", paramName);
            }
        }

        /// <summary>
        /// 验证条件为假，为真时抛出异常
        /// </summary>
        /// <param name="condition">要验证的条件</param>
        /// <param name="paramName">相关的参数名称</param>
        /// <param name="message">错误消息</param>
        /// <exception cref="ArgumentException">条件为真时抛出</exception>
        /// <example>
        /// <code>
        /// ArgumentCustomException.ThrowIfTrue(user.IsDeleted, nameof(user), "不能操作已删除的用户");
        /// ArgumentCustomException.ThrowIfTrue(string.IsNullOrEmpty(token), nameof(token), "访问令牌不能为空");
        /// </code>
        /// </example>
        public static void ThrowIfTrue(bool condition, string paramName, string message)
        {
            if (condition)
            {
                throw new ArgumentException(message ?? "条件验证失败", paramName);
            }
        }

        /// <summary>
        /// 验证参数等于期望值
        /// </summary>
        /// <typeparam name="T">实现 IEquatable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的参数</param>
        /// <param name="expected">期望的值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的参数值</returns>
        /// <exception cref="ArgumentException">参数不等于期望值时抛出</exception>
        /// <example>
        /// <code>
        /// var version = ArgumentCustomException.ThrowIfNotEqual(versionInput, "1.0", nameof(versionInput));
        /// var status = ArgumentCustomException.ThrowIfNotEqual(statusInput, Status.Active, nameof(statusInput), "状态必须为活跃");
        /// </code>
        /// </example>
        public static T ThrowIfNotEqual<T>(T argument, T expected, string paramName, string? message = null)
            where T : IEquatable<T>
        {
            if (!EqualityComparer<T>.Default.Equals(argument, expected))
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 必须等于 {expected}，当前值: {argument}", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证参数不等于指定值
        /// </summary>
        /// <typeparam name="T">实现 IEquatable{T} 接口的类型</typeparam>
        /// <param name="argument">要验证的参数</param>
        /// <param name="notExpected">不期望的值</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的参数值</returns>
        /// <exception cref="ArgumentException">参数等于不期望的值时抛出</exception>
        /// <example>
        /// <code>
        /// var username = ArgumentCustomException.ThrowIfEqual(usernameInput, "admin", nameof(usernameInput));
        /// var id = ArgumentCustomException.ThrowIfEqual(idInput, Guid.Empty, nameof(idInput), "ID不能为空值");
        /// </code>
        /// </example>
        public static T ThrowIfEqual<T>(T argument, T notExpected, string paramName, string? message = null)
            where T : IEquatable<T>
        {
            if (EqualityComparer<T>.Default.Equals(argument, notExpected))
            {
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 不能等于 {notExpected}", paramName);
            }

            return argument;
        }

        /// <summary>
        /// 验证参数包含在指定的值集合中
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="argument">要验证的参数</param>
        /// <param name="validValues">有效值的集合</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的参数值</returns>
        /// <exception cref="ArgumentException">参数不在有效值集合中时抛出</exception>
        /// <example>
        /// <code>
        /// var fileExtension = ArgumentCustomException.ThrowIfNotInSet(extInput, new[] { ".jpg", ".png", ".gif" }, nameof(extInput));
        /// var dayOfWeek = ArgumentCustomException.ThrowIfNotInSet(dayInput, new[] { 1, 2, 3, 4, 5 }, nameof(dayInput), "只支持工作日");
        /// </code>
        /// </example>
        public static T ThrowIfNotInSet<T>(T argument, IEnumerable<T> validValues, string paramName, string? message = null)
        {
            ThrowIfNull(validValues, nameof(validValues));

            if (!validValues.Contains(argument))
            {
                var validValuesStr = string.Join(", ", validValues);
                throw new ArgumentException(
                    message ?? $"参数 {paramName} 必须是以下值之一: [{validValuesStr}]，当前值: {argument}", paramName);
            }

            return argument;
        }

        #endregion

        #region 日期时间验证

        /// <summary>
        /// 验证日期时间在指定范围内
        /// </summary>
        /// <param name="argument">要验证的日期时间</param>
        /// <param name="minDate">最小日期时间（包含）</param>
        /// <param name="maxDate">最大日期时间（包含）</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <returns>验证通过的日期时间</returns>
        /// <exception cref="ArgumentOutOfRangeException">日期时间超出范围时抛出</exception>
        /// <example>
        /// <code>
        /// var birthDate = ArgumentCustomException.ThrowIfDateOutOfRange(birthDateInput, 
        ///     new DateTime(1900, 1, 1), DateTime.Today, nameof(birthDateInput));
        /// var appointmentTime = ArgumentCustomException.ThrowIfDateOutOfRange(appointmentInput, 
        ///     DateTime.Today, DateTime.Today.AddDays(30), nameof(appointmentInput), "预约时间必须在未来30天内");
        /// </code>
        /// </example>
        public static DateTime ThrowIfDateOutOfRange(DateTime argument, DateTime minDate, DateTime maxDate,
            string paramName, string? message = null)
        {
            if (minDate > maxDate)
                throw new ArgumentException("最小日期不能大于最大日期", nameof(minDate));

            if (argument < minDate || argument > maxDate)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 必须在 {minDate:yyyy-MM-dd} 到 {maxDate:yyyy-MM-dd} 之间，当前值: {argument:yyyy-MM-dd}");
            }
            return argument;
        }

        /// <summary>
        /// 验证日期时间不是过去的时间
        /// </summary>
        /// <param name="argument">要验证的日期时间</param>
        /// <param name="paramName">参数名称</param>
        /// <param name="message">自定义错误消息</param>
        /// <param name="tolerance">容差时间，默认为0</param>
        /// <returns>验证通过的日期时间</returns>
        /// <exception cref="ArgumentOutOfRangeException">日期时间是过去时间时抛出</exception>
        /// <example>
        /// <code>
        /// var eventDate = ArgumentCustomException.ThrowIfPastDate(eventDateInput, nameof(eventDateInput));
        /// var expireDate = ArgumentCustomException.ThrowIfPastDate(expireDateInput, nameof(expireDateInput), 
        ///     "过期时间不能是过去时间", TimeSpan.FromMinutes(5));
        /// </code>
        /// </example>
        public static DateTime ThrowIfPastDate(DateTime argument, string paramName, string? message = null,
            TimeSpan tolerance = default)
        {
            var minDate = DateTime.Now.Subtract(tolerance);

            if (argument < minDate)
            {
                throw new ArgumentOutOfRangeException(paramName, argument,
                    message ?? $"参数 {paramName} 不能是过去的时间，当前值: {argument:yyyy-MM-dd HH:mm:ss}");
            }
            return argument;
        }

        #endregion

        #region 高级组合验证

        /// <summary>
        /// 对多个参数执行相同的验证逻辑
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="validator">验证委托</param>
        /// <param name="arguments">参数名称和值的字典</param>
        /// <example>
        /// <code>
        /// ArgumentCustomException.ThrowIfMultiple(
        ///     arg => ArgumentCustomException.ThrowIfNullOrEmpty(arg.Value, arg.Key),
        ///     new Dictionary&lt;string, string&gt;
        ///     {
        ///         { nameof(firstName), firstName },
        ///         { nameof(lastName), lastName },
        ///         { nameof(email), email }
        ///     });
        /// </code>
        /// </example>
        public static void ThrowIfMultiple<T>(Action<KeyValuePair<string, T>> validator,
            IDictionary<string, T> arguments)
        {
            ThrowIfNull(validator, nameof(validator));
            ThrowIfNull(arguments, nameof(arguments));

            foreach (var arg in arguments)
            {
                validator(arg);
            }
        }

        /// <summary>
        /// 链式验证方法，允许对同一参数执行多个验证
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        /// <param name="argument">要验证的参数</param>
        /// <param name="paramName">参数名称</param>
        /// <returns>验证构建器，支持链式调用</returns>
        /// <example>
        /// <code>
        /// var validatedName = ArgumentCustomException.Chain(nameInput, nameof(nameInput))
        ///     .ThrowIfNull()
        ///     .ThrowIfNullOrWhiteSpace()
        ///     .ThrowIfLengthOutOfRange(2, 50)
        ///     .Value;
        /// </code>
        /// </example>
        public static ArgumentValidator<T> Chain<T>(T argument, string paramName)
        {
            return new ArgumentValidator<T>(argument, paramName);
        }

        /// <summary>
        /// 参数验证构建器，支持链式验证调用
        /// </summary>
        /// <typeparam name="T">参数类型</typeparam>
        public class ArgumentValidator<T>
        {
            /// <summary>
            /// 当前验证的参数值
            /// </summary>
            public T Value { get; private set; }

            /// <summary>
            /// 参数名称
            /// </summary>
            public string ParamName { get; private set; }

            internal ArgumentValidator(T value, string paramName)
            {
                Value = value;
                ParamName = paramName;
            }

            /// <summary>
            /// 验证参数不为 null（仅适用于引用类型）
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            /// <exception cref="InvalidOperationException">当 T 不是引用类型时抛出</exception>
            public ArgumentValidator<T> ThrowIfNull(string? message = null)
            {
                // 运行时检查类型是否为引用类型
                if (!typeof(T).IsClass && Nullable.GetUnderlyingType(typeof(T)) == null)
                {
                    throw new InvalidOperationException($"ThrowIfNull 只能用于引用类型或可空值类型，当前类型是: {typeof(T).Name}");
                }

                // 对于引用类型的检查
                if (typeof(T).IsClass)
                {
                    if (Value == null)
                    {
                        throw new ArgumentNullException(ParamName, message ?? $"参数 {ParamName} 不能为 null");
                    }
                }
                // 对于可空值类型的检查
                else if (Nullable.GetUnderlyingType(typeof(T)) != null)
                {
                    if (Value == null)
                    {
                        throw new ArgumentNullException(ParamName, message ?? $"参数 {ParamName} 不能为 null");
                    }
                }

                return this;
            }

            /// <summary>
            /// 验证字符串参数不为 null 或空白
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            /// <exception cref="InvalidOperationException">当 T 不是 string 类型时抛出</exception>
            public ArgumentValidator<T> ThrowIfNullOrWhiteSpace(string? message = null)
            {
                if (typeof(T) != typeof(string))
                {
                    throw new InvalidOperationException($"ThrowIfNullOrWhiteSpace 只能用于 string 类型，当前类型是: {typeof(T).Name}");
                }

                var strValue = Value as string;
                if (string.IsNullOrWhiteSpace(strValue))
                {
                    throw new ArgumentException(message ?? $"参数 {ParamName} 不能为 null、空字符串或只包含空白字符", ParamName);
                }

                return this;
            }

            /// <summary>
            /// 验证字符串参数不为 null 或空
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            /// <exception cref="InvalidOperationException">当 T 不是 string 类型时抛出</exception>
            public ArgumentValidator<T> ThrowIfNullOrEmpty(string? message = null)
            {
                if (typeof(T) != typeof(string))
                {
                    throw new InvalidOperationException($"ThrowIfNullOrEmpty 只能用于 string 类型，当前类型是: {typeof(T).Name}");
                }

                var strValue = Value as string;
                if (string.IsNullOrEmpty(strValue))
                {
                    throw new ArgumentException(message ?? $"参数 {ParamName} 不能为 null 或空字符串", ParamName);
                }

                return this;
            }

            /// <summary>
            /// 验证字符串长度在指定范围内
            /// </summary>
            /// <param name="minLength">最小长度</param>
            /// <param name="maxLength">最大长度</param>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            /// <exception cref="InvalidOperationException">当 T 不是 string 类型时抛出</exception>
            public ArgumentValidator<T> ThrowIfLengthOutOfRange(int minLength, int maxLength, string? message = null)
            {
                if (typeof(T) != typeof(string))
                {
                    throw new InvalidOperationException($"ThrowIfLengthOutOfRange 只能用于 string 类型，当前类型是: {typeof(T).Name}");
                }

                if (Value is string strValue && (strValue.Length < minLength || strValue.Length > maxLength))
                {
                    throw new ArgumentException(
                        message ?? $"参数 {ParamName} 的长度必须在 {minLength} 到 {maxLength} 之间，当前长度: {strValue.Length}",
                        ParamName);
                }

                return this;
            }

            /// <summary>
            /// 验证数值在指定范围内
            /// </summary>
            /// <param name="min">最小值</param>
            /// <param name="max">最大值</param>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            /// <exception cref="InvalidOperationException">当 T 不实现 IComparable{T} 时抛出</exception>
            public ArgumentValidator<T> ThrowIfOutOfRange(T min, T max, string? message = null)
            {
                if (Value is not IComparable<T> comparableValue)
                {
                    throw new InvalidOperationException($"ThrowIfOutOfRange 只能用于实现 IComparable<{typeof(T).Name}> 的类型");
                }

                if (comparableValue.CompareTo(min) < 0 || comparableValue.CompareTo(max) > 0)
                {
                    throw new ArgumentOutOfRangeException(ParamName, Value,
                        message ?? $"参数 {ParamName} 必须在 {min} 到 {max} 之间，当前值: {Value}");
                }

                return this;
            }

            /// <summary>
            /// 验证数值为正数
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            public ArgumentValidator<T> ThrowIfNotPositive(string? message = null)
            {
                if (Value is not IComparable<T> comparableValue)
                {
                    throw new InvalidOperationException($"ThrowIfNotPositive 只能用于实现 IComparable<{typeof(T).Name}> 的类型");
                }

                var defaultValue = default(T);
                if (comparableValue.CompareTo(defaultValue) <= 0)
                {
                    throw new ArgumentOutOfRangeException(ParamName, Value,
                        message ?? $"参数 {ParamName} 必须为正数，当前值: {Value}");
                }

                return this;
            }

            /// <summary>
            /// 验证数值不为负数
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            public ArgumentValidator<T> ThrowIfNegative(string? message = null)
            {
                if (Value is not IComparable<T> comparableValue)
                {
                    throw new InvalidOperationException($"ThrowIfNegative 只能用于实现 IComparable<{typeof(T).Name}> 的类型");
                }

                var defaultValue = default(T);
                if (comparableValue.CompareTo(defaultValue) < 0)
                {
                    throw new ArgumentOutOfRangeException(ParamName, Value,
                        message ?? $"参数 {ParamName} 不能为负数，当前值: {Value}");
                }

                return this;
            }

            /// <summary>
            /// 验证集合不为空
            /// </summary>
            /// <param name="message">自定义错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            public ArgumentValidator<T> ThrowIfEmpty(string? message = null)
            {
                if (Value is IEnumerable enumerable)
                {
                    if (!enumerable.Cast<object>().Any())
                    {
                        throw new ArgumentException(message ?? $"集合参数 {ParamName} 不能为空", ParamName);
                    }
                }
                else if (Value is string strValue)
                {
                    if (string.IsNullOrEmpty(strValue))
                    {
                        throw new ArgumentException(message ?? $"参数 {ParamName} 不能为空字符串", ParamName);
                    }
                }
                else
                {
                    throw new InvalidOperationException($"ThrowIfEmpty 只能用于集合类型或字符串类型，当前类型是: {typeof(T).Name}");
                }

                return this;
            }

            /// <summary>
            /// 验证自定义条件
            /// </summary>
            /// <param name="condition">验证条件</param>
            /// <param name="message">错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            public ArgumentValidator<T> ThrowIf(Func<T, bool> condition, string message)
            {
                ArgumentCustomException.ThrowIfNull(condition, nameof(condition));
                ArgumentCustomException.ThrowIfNullOrWhiteSpace(message, nameof(message));

                if (condition(Value))
                {
                    throw new ArgumentException(message, ParamName);
                }

                return this;
            }

            /// <summary>
            /// 验证自定义条件为假
            /// </summary>
            /// <param name="condition">验证条件</param>
            /// <param name="message">错误消息</param>
            /// <returns>当前验证器实例，支持链式调用</returns>
            public ArgumentValidator<T> ThrowIfNot(Func<T, bool> condition, string message)
            {
                ArgumentCustomException.ThrowIfNull(condition, nameof(condition));
                ArgumentCustomException.ThrowIfNullOrWhiteSpace(message, nameof(message));

                if (!condition(Value))
                {
                    throw new ArgumentException(message, ParamName);
                }

                return this;
            }
        }
        #endregion
    }

}
